// Microsoft.Tools.RegAsm.Abbrevs
using System;
using System.Globalization;
using Microsoft.Tools.RegAsm;

internal class Abbrevs
{
	private string[] m_aOptions;

	private bool[] m_bRequiresValue;

	private bool[] m_bCanHaveValue;

	internal Abbrevs(string[] aOptions)
	{
		m_aOptions = new string[aOptions.Length];
		m_bRequiresValue = new bool[aOptions.Length];
		m_bCanHaveValue = new bool[aOptions.Length];
		for (int i = 0; i < aOptions.Length; i++)
		{
			string text = aOptions[i].ToLower(CultureInfo.InvariantCulture);
			if (text.StartsWith("*", StringComparison.Ordinal))
			{
				m_bRequiresValue[i] = true;
				m_bCanHaveValue[i] = true;
				text = text.Substring(1);
			}
			else if (text.StartsWith("+", StringComparison.Ordinal))
			{
				m_bRequiresValue[i] = false;
				m_bCanHaveValue[i] = true;
				text = text.Substring(1);
			}
			m_aOptions[i] = text;
		}
	}

	internal string Lookup(string strOpt, out bool bRequiresValue, out bool bCanHaveValue)
	{
		bool flag = false;
		int num = -1;
		for (int i = 0; i < m_aOptions.Length; i++)
		{
			if (strOpt.Equals(m_aOptions[i], StringComparison.OrdinalIgnoreCase))
			{
				bRequiresValue = m_bRequiresValue[i];
				bCanHaveValue = m_bCanHaveValue[i];
				return m_aOptions[i];
			}
			if (m_aOptions[i].StartsWith(strOpt, StringComparison.OrdinalIgnoreCase))
			{
				if (flag)
				{
					throw new ApplicationException(Resource.FormatString("Err_AmbigousOption", strOpt));
				}
				flag = true;
				num = i;
			}
		}
		if (flag)
		{
			bRequiresValue = m_bRequiresValue[num];
			bCanHaveValue = m_bCanHaveValue[num];
			return m_aOptions[num];
		}
		throw new ApplicationException(Resource.FormatString("Err_UnknownOption", strOpt));
	}
}
